
/**
  ******************************************************************************
  * Copyright 2021 The Microbee Authors. All Rights Reserved.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * 
  * http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * 
  * @file       uitc_battery_state.h
  * @author     baiyang
  * @date       2022-10-29
  ******************************************************************************
  */

#pragma once

#ifdef __cplusplus
extern "C"{
#endif

/*----------------------------------include-----------------------------------*/
#include <stdint.h>
#include <stdbool.h>

#include <uITC/uITC.h>
/*-----------------------------------macro------------------------------------*/
ITC_DECLARE(battery_state);
ITC_DECLARE(battery2_state);
ITC_DECLARE(battery3_state);
/*----------------------------------typedef-----------------------------------*/
typedef struct {
    uint64_t                    timestamp_us;
    float                       voltage;                   // voltage in volts
    float                       current_amps;              // current in amperes
    float                       consumed_mah;              // total current draw in milliamp hours since start-up
    float                       consumed_wh;               // total energy consumed in Wh since start-up
    float                       temperature;               // battery temperature in degrees Celsius
    float                       temperature_external;      // battery temperature set by an external source in degrees Celsius
    float                       voltage_resting_estimate;  // voltage with sag removed based on current and resistance estimate in Volt
    float                       resistance;                // resistance, in Ohms, calculated by comparing resting voltage vs in flight voltage
    float                       gcs_voltage;               // battery voltage in volts for GCS, may be resting voltage if option enabled
    uint32_t                    last_time_micros;          // time when voltage and current was last read in microseconds
    uint32_t                    low_voltage_start_ms;      // time when voltage dropped below the minimum in milliseconds
    uint32_t                    critical_voltage_start_ms; // critical voltage failsafe start timer in milliseconds
    uint32_t                    temperature_time;          // timestamp of the last received temperature message
    uint32_t                    time_remaining;            // remaining battery time
    uint16_t                    cell_voltages[14];         // battery cell voltages in millivolts, 10 cells matches the MAVLink spec
    int8_t                      failsafe;                     // stage failsafe the battery is in
    int8_t                      charge_state;              // the mavlink charge state. The following mavlink charge states are not used
    int8_t                      capacity_remaining_pct;    // 
    int8_t                      type;                      // 
    bool                        temperature_use;  // 
    bool                        temperature_external_use;  // 
    bool                        has_cell_voltages;         // 
    bool                        healthy;                   // battery monitor is communicating correctly
    bool                        is_powering_off;           // true when power button commands power off
    bool                        powerOffNotified;          // only send powering off notification once
    bool                        has_time_remaining;        // time_remaining is only valid if this is true
    bool                        has_current;
    bool                        has_consumed_energy;
} uitc_battery_state;
/*----------------------------------variable----------------------------------*/

/*-------------------------------------os-------------------------------------*/

/*----------------------------------function----------------------------------*/

/*------------------------------------test------------------------------------*/

#ifdef __cplusplus
}
#endif



